//
// Created by 16933 on 2024/1/11.
//

#ifndef BALANCE_BIKE_CONTROL_H
#define BALANCE_BIKE_CONTROL_H
#include "stm32f1xx_hal.h"
#include "Encoder.h"
#define TURN_LEFT 0
#define TURN_RIGHT 1
#define MID_PWM_DUTY  9

typedef enum
{
    SERVO_TURN_STRIGHT = 0u,
    SERVO_TURN_LEFT,
    SERVO_TURN_RIGHT
} Servo_Diraction;

typedef enum
{
    CLOCKWISE = 0u,
    COUNTERCLOCKWISE
}MomentumWheel_Diraction;

typedef enum
{
    FORWORD = 0u,
    BACKWORD
}DriveWeel_Diraction;
//小车姿态
typedef enum
{

    FALLING = 0,
    BALANCED
} Posture;

typedef struct
{
    MomentumWheel_Diraction diraction;      //转向
    motor_measure_t encoder_controler;      //编码器信息
    float speed_target_rpm;                        //当前速度 （期望）
    int pwm_duty;                           //占空比：0->2000
}MomentumWheel_Controler;

typedef struct
{
    DriveWeel_Diraction diraction;          //前进方向
    float speed;
    float speed_bluetooth;                  //蓝牙控制
    float blutooth_flag;
    int pwm_duty;                           //占空比：0->2000
}DriveWeel_Controler;

typedef struct
{
    int pwm_duty;                           //占空比：0->200
    float trun_angle;                       //转动角度
    Servo_Diraction diraction;              //转向
}Servor_Controler;

typedef  struct
{
    MomentumWheel_Controler momentum_weel;   //动量轮信息
    DriveWeel_Controler drive_weel;          //后轮驱动轮信息
    Servor_Controler turn_weel;              //前轮转向轮信息
}Motor_Controller;


extern Motor_Controller motor;
extern Posture posture;
void MomentumWheel_Disable();
void MomentumWheel_Enable();
void MomentumWheel_Clockwise(int duty);
void MomentumWheel_Counterclockwise(int duty);
void DriveWell_Forward(int duty);
void DriveWeel_Control(DriveWeel_Controler *drive_motor);
void Servo_Control(Servor_Controler *servor_motor);
#endif //BALANCE_BIKE_CONTROL_H
